<!DOCTYPE html>
<!--
Cut-down patched version of Bootstrap's doc style:
http://github.com/twitter/bootstrap/blob/gh-pages/
under http://creativecommons.org/licenses/by/3.0/
-->
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Sisu · Tutorials</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link href="../../assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../assets/css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="../../assets/css/docs.css" rel="stylesheet">
    <link href="../../assets/css/prettify.min.css" rel="stylesheet">

  </head>

  <body data-spy="scroll" data-target=".sisu-docs-sidebar">

    <!-- Navbar
    ================================================== -->
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="brand" href="./index.html"></a>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li class="active">
                <a href="./index.html">Tutorials</a>
              </li>
              <li class="">
                <a href="./javadoc.html">Javadoc</a>
              </li>
              <li class="">
                <a href="./faq.html">FAQ</a>
              </li>
              <li class="">
                <a href="http://eclipse.org/sisu/" target="_blank">Sisu@Eclipse</a>
              </li>
              <li class="">
                <a href="https://github.com/eclipse/sisu.inject/" target="_blank">GitHub</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>


<!-- Subhead
================================================== -->
<header class="jumbotron subhead" id="overview">
  <div class="container">
    <h1>Sisu in 5 minutes</h1>
    <p class="lead">Easy-peasy Guice.</p>
  </div>
</header>


  <div class="container">

    <!-- Tutorial steps
    ================================================== -->
    <div class="row">
      <div class="span3 sisu-docs-sidebar">
        <ul class="nav nav-list sisu-docs-sidenav">
          <li><a href="#ready"><i class="icon-chevron-right"></i> Ready</a></li>
          <li><a href="#code"><i class="icon-chevron-right"></i> Code</a></li>
          <li><a href="#go"><i class="icon-chevron-right"></i> Go!</a></li>
        </ul>
      </div>
      <div class="span9">



        <!-- Ready
        ================================================== -->
        <section id="ready">
          <div class="page-header">
            <h1>What is Sisu?</h1>
          </div>
          <p class="lead">
            Sisu is a set of <a href="http://code.google.com/p/google-guice/">Guice</a> modules that add classpath scanning, auto-binding, and dynamic wiring.
            Together these modules make up the Sisu container, but they can also be used individually.
          </p>
          <p>Let's begin with a simple Maven project, paste the following into a file called 'pom.xml'</p>
<pre class="prettyprint">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project&gt;&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

  &lt;groupId&gt;example&lt;/groupId&gt;
  &lt;artifactId&gt;sisu-5min-demo&lt;/artifactId&gt;
  &lt;version&gt;0-SNAPSHOT&lt;/version&gt;

  &lt;name&gt;Sisu 5-minute demo&lt;/name&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.inject&lt;/groupId&gt;
      &lt;artifactId&gt;guice&lt;/artifactId&gt;
      &lt;version&gt;4.0&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.eclipse.sisu&lt;/groupId&gt;
      &lt;artifactId&gt;org.eclipse.sisu.inject&lt;/artifactId&gt;
      &lt;version&gt;0.3.5&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

&lt;/project&gt;</pre>
        </section>



        <!-- Code
        ================================================== -->
        <section id="code">
          <div class="page-header">
            <h1>What can it do?</h1>
          </div>
          <p class="lead">
            Sisu looks for types annotated with
            <code class="prettyprint">@Named</code>,
            binds them, and wires any missing dependencies.
          </p>
          <p>Paste the following code into a file called 'src/main/java/example/Example.java'</p>
<pre class="prettyprint">
package example;

import java.awt.*;
import java.util.*;
import javax.swing.*;

// Standard JSR330 annotations
import javax.inject.Inject;
import javax.inject.Named;

import com.google.inject.Guice;

// Sisu modules for scanning and wiring
import org.eclipse.sisu.space.SpaceModule;
import org.eclipse.sisu.space.URLClassSpace;
import org.eclipse.sisu.wire.WireModule;

// let's create some simple Swing tabs...

abstract class AbstractTab extends JPanel {}

// Sisu will spot any @Named components

@Named("One")
class ButtonTab extends AbstractTab {
  ButtonTab() {
    add(new JButton("Button"));
  }
}

@Named("Two")
class CheckBoxTab extends AbstractTab {
  CheckBoxTab() {
    add(new JCheckBox("CheckBox"));
  }
}

@Named("Three")
class RadioButtonTab extends AbstractTab {
  RadioButtonTab() {
    ButtonGroup group = new ButtonGroup();
    group.add(new JRadioButton("+1"));
    group.add(new JRadioButton("0"));
    group.add(new JRadioButton("-1"));
    Enumeration&lt;AbstractButton&gt; e = group.getElements();
    while (e.hasMoreElements()) {
      add(e.nextElement());
    }
  }
}

// Sisu will launch @EagerSingleton's on startup

@Named
@org.eclipse.sisu.EagerSingleton
class Example implements Runnable {
  JTabbedPane pane = new JTabbedPane();

  // Sisu spots we want a map of tabs and wires it up for us

  @Inject
  Example(Map&lt;String, AbstractTab&gt; tabs) {

    for (Map.Entry&lt;String, AbstractTab&gt; t:tabs.entrySet()) {
      pane.addTab(t.getKey(), t.getValue());
    }

    SwingUtilities.invokeLater(this);
  }

  public void run() {
    JFrame frame = new JFrame("Sisu 5-minute demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pane, BorderLayout.CENTER);
    frame.setLocation(100, 50);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }

  public static void main(String[] args) {
    ClassLoader classloader = Example.class.getClassLoader();

    Guice.createInjector(
      new WireModule(                       // auto-wires unresolved dependencies
        new SpaceModule(                     // scans and binds @Named components
          new URLClassSpace( classloader )    // abstracts class/resource finding
    )));
  }
}</pre>
        </section>



        <!-- Go!
        ================================================== -->
        <section id="go">
          <div class="page-header">
            <h1>How does it work?</h1>
          </div>
          <p class="lead">
            Sisu has a
            <a href="../api/org.eclipse.sisu.inject/reference/org/eclipse/sisu/space/package-summary.html"><code class="prettyprint">SpaceModule</code></a>
            for scanning and a
            <a href="../api/org.eclipse.sisu.inject/reference/org/eclipse/sisu/wire/package-summary.html"><code class="prettyprint">WireModule</code></a>
            that wires requests to its dynamic
            <a href="../api/org.eclipse.sisu.inject/reference/org/eclipse/sisu/inject/package-summary.html"><code class="prettyprint">BeanLocator</code></a>.
          </p>
          <p>Paste the following Maven command into your console window to launch the demo</p>
<pre class="prettyprint">
mvn compile exec:java -Dexec.mainClass=example.Example</pre>
          <img src="../../assets/img/5min-demo.png"></img>
          <p>If you're interested in what Sisu is doing you can turn on tracing with -Dsisu.debug</p>
        </section>



      </div>
    </div>

  </div>



    <!-- Footer
    ================================================== -->
    <footer class="footer">
      <div class="container">
        <p>Document style adapted from <a href="http://github.com/twitter/bootstrap/blob/gh-pages/">Bootstrap</a> under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
        <p><a href="http://glyphicons.com">Glyphicons Free</a> licensed under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
        <ul class="footer-links">
        </ul>
      </div>
    </footer>



    <script src="../../assets/js/jquery.min.js"></script>
    <script src="../../assets/js/bootstrap.min.js"></script>
    <script src="../../assets/js/prettify.min.js"></script>
    <script src="../../assets/js/docs.js"></script>

  </body>
</html>
